import os
import sys

from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By

from selenium.webdriver.firefox.service import Service as FirefoxService
from selenium.webdriver.common.action_chains import ActionChains
class LikeShopTest():
    
    # def  __init__(self) -> None:
    #     driver_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(sys.executable)))),
    #                            'geckodriver.exe')
    #     service = FirefoxService(executable_path=driver_path)
    #     options = webdriver.FirefoxOptions()
    #     self.browser = webdriver.Firefox(service=service, options=options)

 
    
    def test1(self):
        

        self.browser = webdriver.Edge()
        self.browser.get("http://likeshop.abc/admin/account/login.html")
        sleep(1)
        self.browser.find_element(By.NAME,'account').send_keys('admin')
        self.browser.find_element(By.NAME,'password').send_keys('123456')
        self.browser.find_element(By.NAME,'code').send_keys('11111')
        self.browser.find_element(By.ID,'login').click()
        sleep(3)
        # self.browser.find_element(By.LINK_TEXT,'商品').click()

        # frame1 = self.browser.find_element(By.XPATH,'//*[@id="LAY_app_body"]/div[2]/iframe')
        # self.browser.switch_to.frame(frame1)
        # sleep(1)

        # self.test_shop_add()


    #     # sleep(2)
    #     # self.browser.switch_to.default_content()
    #     # logout_button = self.browser.find_element(By.XPATH,'/html/body/div/div[1]/div[1]/ul[2]/li[3]/a/cite')
    #     # ActionChains(self.browser).move_to_element(logout_button).perform()
    #     # sleep(2)
    #     # self.browser.find_element(By.XPATH,'/html/body/div/div[1]/div[1]/ul[2]/li[3]/dl/dd[2]/a').click()
    #     # sleep(3)
        
    # def test_shop_list(self):
    #     self.browser.find_element(By.XPATH,'//*[@id="keyword"]').send_keys('文具')
    #     sleep(1)
    #     self.query_list('文具')
    #     sleep(3)
    #     self.browser.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/div[1]/div/div[3]/div/div/div/input').click()
    #     sleep(2)
    #     self.browser.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/div[1]/div/div[3]/div/div/dl/dd[3]').click()
    #     self.query_list('晨光')

    # def query_list(self,query_name):
    #     self.browser.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/div[1]/div/div[5]/button[1]').click()
    #     sleep(2)
    #     shop_list =self.browser.find_elements(By.XPATH,'/html/body/div/div/div[2]/div/div/div[2]/div[2]/div[1]/div[2]/table/tbody/tr')
    #     count = len(shop_list)
    #     if count == 0:
    #         print('没有数据')
    #     else:
    #         shop_name_ret = True
    #         for shop_item in shop_list:
    #             shop_name = shop_item.find_element(By.XPATH,'./td[2]/div').text
    #             if query_name not in shop_name:
    #                 shop_name_ret = False
    #         # for i in range(1,count + 1):
    #         #     xpath = '/html/body/div/div/div[2]/div/div/div[2]/div[2]/div[1]/div[2]/table/tbody/tr[%s]/td[2]/div' %i
    #         #     shop_name = self.browser.find_element(By.XPATH,xpath).text
    #         #     if '文具' not in shop_name:
    #         #         shop_name_ret = False
    #         if shop_name_ret:
    #             print('没找到问题')
    #         else:
    #             print('出现bug')
                
    #         def test_shop_add(self):
    #             #点击发布商品
    #             self.browser.find_element(By.XPATH, '/html/body/div[1]/div/div[2]/div/div/div[2]/div[1]/button[1]').click()
    #             sleep(3)
    #             #进入商品发布框架
    #             shop_add_iframe = self.browser.find_element(By.XPATH,' //html/body/div[4]/div[2]/iframe')
    #             self.browser.switch_to.frame(shop_add_iframe)
                
    #             #定位商品名称输入框并输入商品名称
    #             self.browser.find_element(By.XPATH, '/html/body/div/div/div[1]/div/div/div[1]/div/input[2]').send_keys('测试商品')
                
    #             #选择第一个大类
    #             self.browser.find_element(By.XPATH,'/html/body/div/div/div[1]/div/div/div[3]/div[1]/div/div/input').click()
    #             sleep(3)
    #             self.browser.find_element(By.XPATH,'/html/body/div/div/div[1]/div/div/div[3]/div[1]/div/dl/dd[2]').click()


    #             #选择大类下的分类

    #             self.browser.find_element(By.XPATH,'/html/body/div/div/div[1]/div/div/div[3]/div[2]/div/div/input').click()
    #             sleep(1)
    #             self.browser.find_element(By.XPATH,'/html/body/div/div/div[1]/div/div/div[3]/div[2]/div/dl/dd[2]').click()
    #             #选择子类下的分类

    #             self.browser.find_element(By.XPATH,'/html/body/div/div/div[1]/div/div/div[3]/div[2]/div/div/input').click()
    #             sleep(1)
    #             self.browser.find_element(By.XPATH,'/html/body/div/div/div[1]/div/div/div[3]/div[2]/div/dl/dd[2]').click()
    #             sleep(2)





likeshop = LikeShopTest()
likeshop.test1()
